
* CLEAN UP AND STORE THE DATA FILE
keep year cantonid cantonname tu_total total_taxunits total_pop married_pop wea_total  ///
ts90 wea_avg90  P90   b90 ///
ts95 wea_avg95  P95   b95 ///
ts99 wea_avg99  P99   b99 ///
ts995 wea_avg995  P995   b995 ///
ts999 wea_avg999  P999   b999 ///
ts9999 wea_avg9999  P9999   b9999 ///
P10_5  P5_1  P10_1 P1_05 P1_01 P05_01 P01_001 ///
top10_within_top1 top1_within_top1 top10_within_top10 ///
alpha beta


foreach v in tu_total total_taxunits total_pop married_pop wea_total  ///
ts90 wea_avg90  P90   b90 ///
ts95 wea_avg95  P95   b95 ///
ts99 wea_avg99  P99   b99 ///
ts995 wea_avg995  P995   b995 ///
ts999 wea_avg999  P999   b999 ///
ts9999 wea_avg9999  P9999   b9999 ///
P10_5  P5_1  P10_1 P1_05 P1_01 P05_01 P01_001 ///
top10_within_top1 top1_within_top1 top10_within_top10 ///
alpha beta {
replace `v'=. if `v'==0
}

// Gen average wealth per adult and per tax unit
gen avg_wea_adult = wea_total/total_pop
label var avg_wea_adult "Average nominal wealth per adult"
gen avg_wea_taxunit = wea_total/total_taxunits
label var avg_wea_taxunit "Average nominal wealth per tax unit"


// Express monetary variables in millions of CHF
foreach var in ts90 ts95 ts99 ts995 ts999 ts9999 ///
wea_avg90 wea_avg95 wea_avg99 wea_avg995 wea_avg999 wea_avg9999 avg_wea_adult avg_wea_taxunit {
replace `var' = `var'/1000000
}


* genereate a variable with share filing
gen filers = tu_total/total_taxunits
label var filers "Share of population filing"


* ORDER THE DATA
order year P90 P95 P99 P995 P999 P9999  ///
				P10_5 P5_1 P10_1 P1_05 P1_01 P05_01 P01_001 ///
				ts90 ts95 ts99 ts995 ts999 ts9999 ///
				wea_avg90 wea_avg95 wea_avg99 wea_avg995 wea_avg999 wea_avg9999 ///
				top10_within_top1 top1_within_top1 top10_within_top10   alpha beta  ///
				tu_total wea_total total_pop total_taxunits filers  ///
				avg_wea_adult avg_wea_taxunit 
				
sort cantonid year
xtset cantonid year, yearly delta(1)

